import {get} from '@/api/index'
import commonUtil from "@/utils/commonUtil";

/**
 * 获取行业信息
 */
const industryCategoryQueryAll = () => {
    return get("/sys/industryCategory/queryAll");
}

/**
 * 获取地区信息
 * @param parentId
 * @returns {Promise}
 */
const areaQuery = (parentId) => {
    return get("/sys/area/query", {parentId: parentId});
}

/**
 * 获取全部信息
 */
const areaQueryAll = () => {
    return get("/sys/area/queryAll");
}

/**
 * 获取字典表
 */
const dictionaryQueryByType = (type) => {
    return get("/sys/dictionary/query",{type:type});
}

/**
 * 获取动态类型
 */
const dictionaryTypeQueryList= (state) => {
    return get("/dynamic/dynamicType/queryList",{state:state});
}

/**
 * 获取用户信息
 * @returns {*}
 */
const getUserInfo = () => {
    return new Promise((resolve, reject) => {
        let userInfo;
        if (sessionStorage.getItem("userInfo") != null) {
            userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
            resolve(userInfo);
        } else {
            get("/user/details/getUserInfo").then((res) => {
                userInfo = res.data;
                sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
                resolve(userInfo);
            }).catch(err => {
                sessionStorage.removeItem("userInfo");
                reject(userInfo);
            })
        }

    });
}

export default {
    industryCategoryQueryAll,
    areaQuery,
    getUserInfo,
    areaQueryAll,
    dictionaryQueryByType,
    dictionaryTypeQueryList
}